import React, { Component } from 'react'
import styles from './Header.module.scss'
import gongGao from './../../images/gonggao.png'
import keTi from './../../images/keti.png'
import wenJian from './../../images/wenjian.png'
import {withRouter} from "react-router-dom"


class Header extends Component {

  onAdviceMore(e) {
    this.props.history.push('/mainPage/main/headerList?item=advice')
    e.stopPropagation();
  }

  onCourseMore(e) {
    this.props.history.push('/mainPage/main/headerList?item=course')
    e.stopPropagation();
  }

  onFileMore(e) {
    this.props.history.push('/mainPage/main/headerList?item=file')
    e.stopPropagation();
  }

  onInfo(item) {
    if (item) {
      this.props.history.push(`/mainPage/pageDetail/advice/${item.id}`)
    }
  }

  render() {
    const { data }= this.props
    return (
      <div className={styles.header}>
        <div className={styles.item}>
          <img src={gongGao} alt=""/>
          <div>
            <span className={styles.last} onClick={() => this.onInfo(data.advice[0])}>
              {(data.advice[0] && data.advice[0].title) || ''}
              <span className={styles.more} onClick={e => this.onAdviceMore(e)}>更多</span>
            </span>
          </div>
        </div>
        <div className={styles.item}>
          <img src={keTi} alt=""/>
          <div>
            <span className={styles.last} onClick={() => this.onInfo(data.course[0])}>
              {(data.course[0] && data.course[0].name) || ''}
              <span className={styles.more} onClick={e => this.onCourseMore(e)}>更多</span>
            </span>
          </div>
        </div>
        <div className={styles.item}>
          <img src={wenJian} alt=""/>
          <div>
            <span className={styles.last} onClick={() => this.onInfo(data.files[0])}>
              {(data.files[0] && data.files[0].title) || ''}
              <span className={styles.more} onClick={e => this.onFileMore(e)}>更多</span>
            </span>
          </div>
        </div>
      </div>
    )
  }
}
export default withRouter(Header);
